package com.scn.base.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class ApplicationContextListener  implements ServletContextListener,HttpSessionListener  {
	private Logger log=Logger.getLogger(this.getClass());
	public void contextDestroyed(ServletContextEvent sce) {
		
	}

	public void contextInitialized(ServletContextEvent sce) { 
		log.info("加载Spring ApplicationContext...");
		ApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
		ApplicationContextUtil.setContext(wac);
		log.info("加载Spring ApplicationContext END");
	}

	public void sessionCreated(HttpSessionEvent arg0) {
		ApplicationContextUtil.addSessionCount();
	}

	public void sessionDestroyed(HttpSessionEvent arg0) {
		ApplicationContextUtil.plusSessionCount();
	}

}
